const http = uni.$u.http
// 接口，分类，操作

// post请求，获取菜单
export const postMenu = (params, config = {}) => http.post('/ebapi/public_api/index', params, config)

// get请求，获取菜单，注意：get请求的配置等，都在第二个参数中，详见前面解释
export const getMenu = (data) => http.get('/ebapi/public_api/index', data)

// get请求，获取首页
export const getIndex = (params = {}) => http.get('/api/index', params)

// 认证相关的
export const authLogin = params => http.post('/api/auth/login', params)
export const authRegister = params => http.post('/api/auth/register', params)
export const authLogout = () => http.post('/api/auth/logout')
export const authOssToken = () => http.get('/api/auth/oss/token')

// 用户相关的
export const getUserInfo = () => http.get('/api/user')
export const userInfoUpdate = (params) => http.put('/api/user', params)
export const userAvatarUpdate = (params) => http.patch('/api/user/avatar', params)

// 商品相关的
export const goodsDetail = id => http.get('/api/goods/' + id ) // 商品详情
export const goodsCollect = id => http.post('/api/collects/goods/' + id) // 商品收藏
export const goodsCollects = params => http.get('/api/collects', params) // 收藏列表
export const goodsList = (params = {}) => http.get('/api/goods', params) // 商品列表

// 购物车相关
export const cartsAdd = params => http.post('/api/carts', params) // 加入购物车
export const cartsList = (query = {}) => http.get('/api/carts/', query) // 购物车列表
export const cartsChecked = (params) => http.patch('/api/carts/checked', params) // 购物车改变选中
export const cartsRemove = id => http.delete('/api/carts/' + id ) // 移出购物车
export const cartsNum = (id, params) => http.put('/api/carts/' + id, params) // 购物车数量改变

// 订单相关的
export const ordersPreview = () => http.get('/api/orders/preview')  // 订单预览数据
export const ordersList = params => http.get('/api/orders', params) // 订单列表
export const ordersPost = params => http.post('/api/orders/', params) // 提交订单
export const ordersDetail = (id, params) => http.get('/api/orders/' + id, params) // 订单详情

// 地址相关的
export const addressList = () => http.get('/api/address') // 地址列表
export const addressRemove = id => http.delete('/api/address/' + id) // 删除地址
export const addressDefault = id => http.patch('/api/address/' + id + '/default') // 设置为默认地址
export const addressAdd = params => http.post('/api/address', params) // 添加地址
